package com.hdy.orderforthree.widget;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.hdy.net.order.bean.LoginBean;
import com.hdy.net.order.bean.TablesBean;
import com.hdy.orderforthree.R;
import com.hdy.orderforthree.R2;
import com.hdy.orderforthree.pos.ConcretePosFactory;

import butterknife.BindView;

public class PeopleNumberDialogPop extends CenterDialogPop {

    @BindView(R2.id.people_number_minus)
    ImageView mPeopleNumberMinus;
    @BindView(R2.id.people_number)
    TextView mPeopleNumber;
    @BindView(R2.id.people_number_plus)
    ImageView mPeopleNumberPlus;
    @BindView(R2.id.people_number_1)
    TextView mPeopleNumber1;
    @BindView(R2.id.people_number_2)
    TextView mPeopleNumber2;
    @BindView(R2.id.people_number_3)
    TextView mPeopleNumber3;
    @BindView(R2.id.people_number_4)
    TextView mPeopleNumber4;
    @BindView(R2.id.people_number_5)
    TextView mPeopleNumber5;
    @BindView(R2.id.people_number_6)
    TextView mPeopleNumber6;
    @BindView(R2.id.people_number_10)
    TextView mPeopleNumber10;
    @BindView(R2.id.people_number_15)
    TextView mPeopleNumber15;
    @BindView(R2.id.people_number_20)
    TextView mPeopleNumber20;
    @BindView(R2.id.people_number_25)
    TextView mPeopleNumber25;
    @BindView(R2.id.people_number_confirm)
    TextView mPeopleNumberConfirm;

    public PeopleNumberDialogPop(Context context) {
        super(R.layout.confirm_people_number,context);

        initView();
    }

    private void initView() {
        mPeopleNumberMinus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int number = Integer.parseInt(mPeopleNumber.getText().toString());
                if (number > 1) {
                    mPeopleNumber.setText(String.valueOf((number - 1)));
                }
            }
        });

        mPeopleNumberPlus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int number = Integer.parseInt(mPeopleNumber.getText().toString());
                mPeopleNumber.setText(String.valueOf((number + 1)));
            }
        });

        mPeopleNumber1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setPeopleNumber((TextView) v);
            }
        });

        mPeopleNumber1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setPeopleNumber((TextView) v);
            }
        });

        mPeopleNumber2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setPeopleNumber((TextView) v);
            }
        });

        mPeopleNumber3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setPeopleNumber((TextView) v);
            }
        });

        mPeopleNumber4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setPeopleNumber((TextView) v);
            }
        });

        mPeopleNumber5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setPeopleNumber((TextView) v);
            }
        });

        mPeopleNumber6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setPeopleNumber((TextView) v);
            }
        });

        mPeopleNumber10.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setPeopleNumber((TextView) v);
            }
        });

        mPeopleNumber15.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setPeopleNumber((TextView) v);
            }
        });

        mPeopleNumber20.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setPeopleNumber((TextView) v);
            }
        });

        mPeopleNumber25.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setPeopleNumber((TextView) v);
            }
        });

        mPeopleNumberConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int number = Integer.parseInt(mPeopleNumber.getText().toString());
                LoginBean loginBean = ConcretePosFactory.getInstance().getPos().getLoginBean();
                if (loginBean.getTables() == null) {
                    loginBean.setTables(new TablesBean());
                }
                loginBean.getTables().setNumber(number);
                ConcretePosFactory.getInstance().getPos().saveLoginBean(loginBean);
                if (mUpdateViewCallback != null) {
                    mUpdateViewCallback.showPeopleNumber();
                }

                //关闭弹框
                removeView();
            }
        });
    }

    private void setPeopleNumber(TextView v) {
        int number = Integer.parseInt(v.getText().toString());
        mPeopleNumber.setText(String.valueOf((number)));
    }
}
